[Memory64] Replace int (used as ptr) with long in tests - #14613
Conversation
kripken
left a comment
There was a problem hiding this comment.
In general this sounds good. I don't have a better idea than long here myself. But curious if others have ideas.
To be sure, the title says "replace int with long", but this only replaces the ints used as pointers, as implied in the description?
lgtm % those + the comment
|
|
||
| int main() { | ||
| return (int)memchr("hello", 'z', 7); | ||
| return (int)(long)memchr("hello", 'z', 7); |
There was a problem hiding this comment.
Why do two casts here? (happens in a few more tests too)
There was a problem hiding this comment.
because casting a 64-bit pointer straight to int results in a warning/error
There was a problem hiding this comment.
I would use intptr_t here .. it seems like just what that type is designed for .. and it should work with just a single cast I think.
There was a problem hiding this comment.
@sbc100 how? intptr_t is 64-bit.. that won't let itself be passed to an int context without warning/error.
|
|
||
| bool __attribute__((noinline)) DOS_Device::Read(unsigned char * data,unsigned short * size) { | ||
| printf("DOS_Device::Read (this = %i)\n", (int)this); | ||
| printf("DOS_Device::Read (this = %ld)\n", (long)this); |
There was a problem hiding this comment.
This should just be %p with no cast, no? Same wherever we want to printf a pointer.
There was a problem hiding this comment.
Yup, that be better.. I was just trying to fix the existing style which seems to like to cast to int.
411 results for %ld (most of which "pointers", only 115 of which from PR) - might want to leave this improvement for another PR though.
There was a problem hiding this comment.
Maybe lets land that first? That would make this PR a lot smaller. I can have a go at it if you like?
There was a problem hiding this comment.
Wouldn't that produce a ton of conflicts with this PR?
I don't think we should mix trying to make things 64-bit compatible with general large scale cleanup of tests. I am sure if you go look at the tests you can find a lot of things to clean up.
There was a problem hiding this comment.
I think its good to do such cleanups when it becomes apparent that they are useful/needed. In this case doing the cleanup ahead of time will significantly reduce the size of, and churn generated by, this PR.
Yes it will conflict with this PR but it should be trivial to just run git checkout --thiers to accept the upstream changes since we know we want to basically revert all the conflicting parts of this PR, right?
There was a problem hiding this comment.
(i.e. there should be no manual conflict resolution needed I think)
| int main() { | ||
| // Create initial threads. | ||
| for(int i = 0; i < NUM_THREADS; ++i) { | ||
| for(long i = 0; i < NUM_THREADS; ++i) { |
There was a problem hiding this comment.
I think you can leave this as int, no?
There was a problem hiding this comment.
I was just trying to make the code work with as few casts as possible. Since the thread id is stored as a long/pointer, it seemed nicer to make this loop use long instead of int.
sbc100
left a comment
There was a problem hiding this comment.
I would rather use intptr_t where is makes sense. I don't feel too strongly about this, but I would certainly like to see printf use %p for pointers where possible.
| assert(argc == 1); | ||
| pc = (char *)alloca(4+argc); | ||
| assert(((int)pc) % 4 == 0); | ||
| assert(((long)pc) % 4 == 0); |
There was a problem hiding this comment.
Is this case needed? Can't it just be removed?
There was a problem hiding this comment.
Was just trying to fix the existing test for 64-bit. It probably shouldn't be removed since this also still runs for 32-bit.
| long get_stack() { int i; return (long)&i; } | ||
| int uses_stack(test_struct* t1) { | ||
| if (stackChecker == 0) stackChecker = (int*)malloc(sizeof(int)); | ||
| if (stackChecker == 0) stackChecker = (long*)malloc(sizeof(long)); |
There was a problem hiding this comment.
I can't see why we use malloc at all here.. why not just have static intptr_t stackChecker = 0 and avoid the malloc completely? (just store the value in memory)
There was a problem hiding this comment.
I was not trying to fix the actual tests, just make this 64-bit compatible. I can fix this also if you want, but it would not make this PR a wasm32 NFC as intended.
| } | ||
|
|
||
| volatile int fetch_and_or_data = 0; | ||
| volatile long fetch_and_or_data = 0; |
There was a problem hiding this comment.
This seems like maybe it could be changing what we are testing here?
There was a problem hiding this comment.
I was assuming there's equivalent 64-bit atomic ops for this, any reason why not?
|
Browser CI fails on |
|
Also an error in 3rd-party code (poppler?) unrelated to this PR it seems: |
|
and a |
sbc100
left a comment
There was a problem hiding this comment.
We talking offline, and I'm good with doing a cleanup of our printf() usage as a followup.
There are a lot of places where pointers get cast to int, and to prepare for further Memory64 changes, those are changed to long. I chose long since it is most similar to the existing int, instead of e.g intptr_t, since long is more universal (there are many cases where the actual data stored is not a pointer). Since under wasm32 int and long are equal, this should in theory be a NFC for wasm32, making it easier to review. It also allows #12869 to be smaller
There are a lot of places where pointers get cast to int, and to prepare for further Memory64 changes, those are changed to long.
I chose long since it is most similar to the existing int, instead of e.g intptr_t, since long is more universal (there are many cases where the actual data stored is not a pointer).
Since under wasm32 int and long are equal, this should in theory be a NFC for wasm32, making it easier to review.
It also allows #12869 to be smaller